
MidnightStreamer API
Server API

    Lines
    MAGs
    Administrators
    Resellers
    Servers
    Streams
    Panel

Player API
Hooks

--Lines

SERVER API LINES

To successfully use the Server API, you have to insert your IP first into the whitelist. You can do that in General Settings -> API Settings.

You can pass api_key by POST or by appending the key as 4th segment to the URL.

Creating New Line

To create a New line, we will call the following URL.

http(s)://domain:port/api/line/new

The above URL, accepts the POST action

Example Code:

<?php

$panel_url = 'http://DOMAIN:PORT/';
$api_key = 'api_key';
$username = 'test_username';
$password = 'test_password';
$max_connections = 1;
$restreamer = 1;
$subscription_plan = 1;
$expire_date = strtotime( "+1 month" );

###############################################################################
$post_data = array('api_key' => $api_key,
        	   'data' => array('username' => $username,
				  'password' => $password,
        			  'max_allowed_connections' => $max_connections,
        			  'restreamer' => $restreamer,
        			  'expire_date' => $expire_date,
        			  'subscription_plan_id' => $subscription_plan)
		  );

$opts = array( 'http' => array(
        'method' => 'POST',
        'header' => 'Content-type: application/x-www-form-urlencoded',
        'content' => http_build_query( $post_data ) ) );

$context = stream_context_create( $opts );
$api_result = json_decode( file_get_contents( $panel_url . "api/line/new", false, $context ) );

?>

 

If you leave the username and/or password elements empty, the system will generate random characters for these 2 fields. In addition, leaving any field empty, api will use the default value for this field according to SQL Database. So theoretically, you can make a line with just Calling the Above URL, without any parameter, however the created user, wont have any subscription_plan.

You can call any other element that is in the database like: 

    reseller_id
    disabled
    allowed_ips
    allowed_user_agents
    server_id
    isp_lock
    notes
    and so on...

If you want to set the allowed_ips/allowed_user_agents or other multiple values you can use arrays.

The API will return a simple json encoded string that upon decoding will contain the element result which returns true/false.

Example(API Success)

{"result":true,"created_id":14838,"username":"d4PSc7uCqF","password":"2ZiSRRZk4b"}

The API returned as the username/password of the NEW line, as well as the ID so we can use it wherever we want.

 

Example(API Failed)

{"result":false,"error":"Username exists."}
{"result":false,"error":"{Database error}"}

    Username exists. 
    The Username you specified already exists in the database
    {Database error}
    Database error description. The DB error will be logged in LOGS -> Panel Error Log.

Editing Line

Editing a line is very similar to the above. The URL we will call this time is

http(s)://domain:port/api/line/update

REQUIRED PARAMETERS

    username

OPTIONAL PARAMETERS

    all other fields of lines database table

For example if we want to Edit the Expire Date, make the line restreamer and adjusting the max connections to 10 we will do it like this:

<?php

$panel_url = 'http://DOMAIN:PORT/';
$api_key = 'api_key';
$username = 'test_username';
$password = 'test_password';
$max_connections = 10;
$restreamer = 1;
$expire_date = strtotime( "+1 month" ); //from the time now, not from line's expire date.

###############################################################################
$post_data = array(
        'api_key' => $api_key,
        'username' => $username,
        'data' => array('password' => $password,
        		'max_allowed_connections' => $max_connections,
        		'restreamer' => $restreamer,
        		'expire_date' => $expire_date)
		       );

$opts = array( 'http' => array(
        'method' => 'POST',
        'header' => 'Content-type: application/x-www-form-urlencoded',
        'content' => http_build_query( $post_data ) ) );

$context = stream_context_create( $opts );
$api_result = json_decode( file_get_contents( $panel_url . "api/line/update", false, $context ) );

?>

 

In the above example, we will edit the max_allowed_connections, restreamer and expire_date for our line with username test_username that already exists in our database.

Example(API Success)

{"result":true, "modified_id":{id}, "username":{username}, "password":{password}}

 

Example(API Failed)

{"result":false,"error":"Username doesn't exist."}
{"result":false,"error":"{Database error}"}

    Username doesn't exist. 
    The Username you specified don't exist in the database
    {Database error}
    Database error description. The DB error will be logged in LOGS -> Panel Error Log.

 

Deleting Line

With this API call you can delete the line from the database.

The URL we will call is

http(s)://domain:port/api/line/delete

REQUIRED PARAMETERS

    username

 

View Line Information

With this API call, we will get all the information available about our line including the active connections.

The URL we will call this time is

http(s)://domain:port/api/line/info

REQUIRED PARAMETERS

    username

It will return a JSON Encoded string, with all information that you might want.

Example Code:

$panel_url = 'http://DOMAIN:PORT/';
$api_key = "api_key";
$username = "username";

###############################################################################
$post_data = array( 'api_key' => $api_key, 'username' => $username);
$opts = array( 'http' => array(
        'method' => 'POST',
        'header' => 'Content-type: application/x-www-form-urlencoded',
        'content' => http_build_query( $post_data ) ) );

$context = stream_context_create( $opts );
$api_result = json_decode( file_get_contents( $panel_url . "api/line/info", false, $context ), true );

if ( $api_result['result'] )
{
    echo "Line Connections: " . json_encode($api_result['conn_info']);
    echo "\nCurrent Expire Date: " . (( empty( $api_result['info']['expire_date'] ) ) ? 'Unlimited' : $api_result['info']['expire_date'] );
    echo "\nMax Connections: " . $api_result['info']['max_allowed_connections'];
    echo "\nAvailable Channel IDs: " . implode( ',', $api_result['channel_ids'] );
}
else
    echo 'FAILED';
	
--MAGs


All rights are reserved to DA Streamz © 2025
MidnightStreamer API
SERVER API MAGS

To successfully use the Server API, you have to insert your IP first into the whitelist. You can do that in General Settings -> API Settings.

You can pass api_key by POST or by appending the key as 4th segment to the URL.

Create/Edit & View Information on MAG Devices

The procedure is almost the same as creating/editing & view info on a user line. The only difference is that instead of calling the  user action, we will the stb action. Instead of username we will just pass the mac_address parameter.

 

Example API Call To Create New MAG

http(s)://domain:port/api/mag/new

REQUIRED PARAMETERS

    mac_address

<?php

$panel_url = 'http://DOMAIN:PORT/';
$api_key = 'api_key';
$mac_address = '00:1A:79:79:79:79';
$subscription_plan = 1;
$expire_date = strtotime( "+1 month" );

###############################################################################
$post_data = array(
        'api_key' => $api_key,
        'data' => array('mac_address' => $mac_address,
        		'expire_date' => $expire_date,
        		'subscription_plan_id' => $subscription_plan)
		        );

$opts = array( 'http' => array(
        'method' => 'POST',
        'header' => 'Content-type: application/x-www-form-urlencoded',
        'content' => http_build_query( $post_data ) ) );

$context = stream_context_create( $opts );
$api_result = json_decode( file_get_contents( $panel_url . "api/mag/new", false, $context ) );
print_r($api_result);

?>

Example(API Success)

{"result":true}

 

Example(API Failed)

{"result":false,"error":"MAC Address already exists"}
{"result":false,"error":"{Database error}"}

    MAC Address already exists 
    The MAC already exists in the database
    {Database error}
    Database error description. The DB error will be logged in LOGS -> Panel Error Log.

 

Example API Call To Edit a MAG Device

http(s)://domain:port/api/mag/update

REQUIRED PARAMETERS

    mac_address

<?php

$panel_url = 'http://DOMAIN:PORT/';
$api_key = 'api_key';
$mac_address = '00:1A:79:79:79:79';
$subscription_plan = 1;
$expire_date = strtotime( "+1 month" );

###############################################################################
$post_data = array( 
	'api_key' => $api_key,
	'mac_address' => $mac_address,
	'data' => array('expire_date' => $expire_date,
			'subscription_plan_id' => $subscription_plan)
		);

$opts = array( 'http' => array(
        'method' => 'POST',
        'header' => 'Content-type: application/x-www-form-urlencoded',
        'content' => http_build_query( $post_data ) ) );

$context = stream_context_create( $opts );
$api_result = json_decode( file_get_contents( $panel_url . "api/mag/update", false, $context ) );
?>

Example(API Success)

{"result":true}

 

Example(API Failed)

{"result":false,"error":"Invalid MAC Address"}
{"result":false,"error":"{Database error}"}

    Invalid MAC Address
    Invalid MAC Address format used
    {Database error}
    Database error description. The DB error will be logged in LOGS -> Panel Error Log.

 

Example API Call To Delete a MAG Device

With this API call you can delete the MAG device from the database.

The URL we will call is

http(s)://domain:port/api/mag/delete

REQUIRED PARAMETERS

    mac_address

 

View Information MAG Device

http(s)://domain:port/api/mag/info

REQUIRED PARAMETERS

    mac_address

It will return a JSON Encoded string, with all information that you might want.

Example Code:

<?php

$panel_url = 'http://DOMAIN:PORT/';
$api_key = 'api_key';
$mac_address = '00:1A:79:79:79:79';

###############################################################################
$post_data = array( 'api_key' => $api_key, 'mac_address' => $mac_address);
$opts = array( 'http' => array(
        'method' => 'POST',
        'header' => 'Content-type: application/x-www-form-urlencoded',
        'content' => http_build_query( $post_data ) ) );

$context = stream_context_create( $opts );
$api_result = json_decode( file_get_contents( $panel_url . "api/mag/info", false, $context ), true );


if ( $api_result['result'] )
{
    echo "MAG Connections: " . json_encode($api_result['conn_info']);
    echo "\nCurrent Expire Date: " . ( ( empty( $api_result['info']['expire_date'] ) ) ? 'Unlimited' : $api_result['info']['expire_date'] );
    echo "\nMax Connections: " . $api_result['info']['max_allowed_connections'];
    echo "\nAvailable Channel IDs: " . implode( ',', $api_result['channel_ids'] );
}
else
    echo 'FAILED';

?>


--Administrators


All rights are reserved to DA Streamz © 2025
MidnightStreamer API
SERVER API ADMINISTRATORS

To successfully use the Server API, you have to insert your IP first into the whitelist. You can do that in General Settings -> API Settings.

You can pass api_key by POST or by appending the key as 4th segment of the URL.

Add New Administrator

To add a New administrator, we will call the following URL.

http(s)://domain:port/api/administrators/new

REQUIRED PARAMETERS

    username
    password
    email
    group_id

It will return a JSON Encoded string, with all information that you might want.

Example Code:

$panel_url = 'http://DOMAIN:PORT/';
$api_key = 'api_key';
$username = 'test_username';
$password = 'test_password';
$email = 'user@email.com';
$group_id = X;
$reseller_id = X;

###############################################################################
$post_data = array('api_key' => $api_key,
		   'data' => array('username' => $username, 
		   		   'password' => $password,
		   		   'email' => $email,
		   		   'group_id' => $group_id,
		   		   'reseller_id' => $reseller_id)
		   );

$opts = array( 'http' => array(
        'method' => 'POST',
        'header' => 'Content-type: application/x-www-form-urlencoded',
        'content' => http_build_query( $post_data ) ) );

$context = stream_context_create( $opts );
$api_result = json_decode( file_get_contents( $panel_url . "api/administrators/new", false, $context ), true );

 

Edit Administrator

To edit an existing administrator, we will call the following URL.

http(s)://domain:port/api/administrators/update

REQUIRED PARAMETERS

    id OR username

It will return a JSON Encoded string, with all information that you might want.

Example Code:

$panel_url = 'http://DOMAIN:PORT/';
$api_key = 'api_key';
$id = X;
$email = 'user@email.com';

###############################################################################
$post_data = array( 'api_key' => $api_key, 'id' => $id, 'data' => array('email' => $email) );
$opts = array( 'http' => array(
        'method' => 'POST',
        'header' => 'Content-type: application/x-www-form-urlencoded',
        'content' => http_build_query( $post_data ) ) );

$context = stream_context_create( $opts );
$api_result = json_decode( file_get_contents( $panel_url . "api/administrators/update", false, $context ), true );

 

List Panel Administrators

Perform this request to view all administrators along with their email, username, group, reseller etc.

The URL we will call is

http(s)://domain:port/api/administrator/list

REQUIRED PARAMETERS

    none

It will return a JSON Encoded string, with all information that you might want.

Example Code:

$panel_url = 'http://DOMAIN:PORT/';
$api_key = 'api_key';

###############################################################################
$post_data = array( 'api_key' => $api_key );
$opts = array( 'http' => array(
        'method' => 'POST',
        'header' => 'Content-type: application/x-www-form-urlencoded',
        'content' => http_build_query( $post_data ) ) );

$context = stream_context_create( $opts );
$api_result = json_decode( file_get_contents( $panel_url . "api/administrators/list", false, $context ), true );

--Resellers


All rights are reserved to DA Streamz © 2025
MidnightStreamer API
SERVER API RESELLERS

To successfully use the Server API, you have to insert your IP first into the whitelist. You can do that in General Settings -> API Settings.

You can pass api_key by POST or by appending the key as 4th segment of the URL.

Add New Reseller

To add a New reseller, we will call the following URL.

http(s)://domain:port/api/resellers/new

REQUIRED PARAMETERS

    name

It will return a JSON Encoded string, with all information that you might want.

Example Code:

$panel_url = 'http://DOMAIN:PORT/';
$api_key = 'api_key';
$name = 'test_reseller';
$max_allowed_connections = X;
$use_credits = True;
$credits = X;

###############################################################################
$post_data = array('api_key' => $api_key,
		   'data' => array('name' => $name, 
		   		   'max_allowed_connections' => $max_allowed_connections,
		   		   'use_credits' => $use_credits,
		   		   'credits' => $credits)
		   );

$opts = array( 'http' => array(
        'method' => 'POST',
        'header' => 'Content-type: application/x-www-form-urlencoded',
        'content' => http_build_query( $post_data ) ) );

$context = stream_context_create( $opts );
$api_result = json_decode( file_get_contents( $panel_url . "api/resellers/new", false, $context ), true );

 

Edit Reseller

To edit an existing reseller, we will call the following URL.

http(s)://domain:port/api/resellers/update

REQUIRED PARAMETERS

    id OR username

It will return a JSON Encoded string, with all information that you might want.

Example Code:

$panel_url = 'http://DOMAIN:PORT/';
$api_key = 'api_key';
$id = X;
$credits = X;

###############################################################################
$post_data = array( 'api_key' => $api_key, 'id' => $id, 'data' => array('credits' => $credits) );
$opts = array( 'http' => array(
        'method' => 'POST',
        'header' => 'Content-type: application/x-www-form-urlencoded',
        'content' => http_build_query( $post_data ) ) );

$context = stream_context_create( $opts );
$api_result = json_decode( file_get_contents( $panel_url . "api/resellers/update", false, $context ), true );

 

Add Credits to Reseller

To add credits to an existing reseller, we will call the following URL.

http(s)://domain:port/api/resellers/add_credits

REQUIRED PARAMETERS

    id OR username
    credits

It will return a JSON Encoded string, with all information that you might want.

Example Code:

$panel_url = 'http://DOMAIN:PORT/';
$api_key = 'api_key';
$id = X;
$credits = X;

###############################################################################
$post_data = array( 'api_key' => $api_key, 'id' => $id, 'credits' => $credits);
$opts = array( 'http' => array(
        'method' => 'POST',
        'header' => 'Content-type: application/x-www-form-urlencoded',
        'content' => http_build_query( $post_data ) ) );

$context = stream_context_create( $opts );
$api_result = json_decode( file_get_contents( $panel_url . "api/resellers/add_credits", false, $context ), true );

 

List Panel Resellers

Perform this request to view all resellers along with their email, username, group, reseller etc.

The URL we will call is

http(s)://domain:port/api/reseller/list

REQUIRED PARAMETERS

    none

It will return a JSON Encoded string, with all information that you might want.

Example Code:

$panel_url = 'http://DOMAIN:PORT/';
$api_key = 'api_key';

###############################################################################
$post_data = array( 'api_key' => $api_key );
$opts = array( 'http' => array(
        'method' => 'POST',
        'header' => 'Content-type: application/x-www-form-urlencoded',
        'content' => http_build_query( $post_data ) ) );

$context = stream_context_create( $opts );
$api_result = json_decode( file_get_contents( $panel_url . "api/resellers/list", false, $context ), true );

--Servers


All rights are reserved to DA Streamz © 2025
MidnightStreamer API
SERVER API SERVERS

To successfully use the Server API, you have to insert your IP first into the whitelist. You can do that in General Settings -> API Settings.

You can pass api_key by POST or by appending the key as 4th segment to the URL.

List Servers

Perform this request to view all your servers, main & load balancers including their status.

http(s)://domain:port/api/servers/list/{api_key}

View the details of a single server with its ID.

http(s)://domain:port/api/servers/list/{api_key}/{server_id}

No POST action is required

Editing Server

http(s)://domain:port/api/servers/update

REQUIRED PARAMETERS

    id

OPTIONAL PARAMETERS

    all other fields of servers database table

For example if we want to Edit a LB's IP and VPN IP we will do it like this:

<?php

$panel_url = 'http://DOMAIN:PORT/';
$api_key = 'api_key';
$id = 2;
$server_ip = 1.2.3.4;
$vpn_ip = 10.10.0.8;

###############################################################################
$post_data = array(
        'api_key' => $api_key,
        'id' => $id,
        'data' => array('server_ip' => $server_ip,
        		'vpn_ip' => $vpn_ip)
		       );

$opts = array( 'http' => array(
        'method' => 'POST',
        'header' => 'Content-type: application/x-www-form-urlencoded',
        'content' => http_build_query( $post_data ) ) );

$context = stream_context_create( $opts );
$api_result = json_decode( file_get_contents( $panel_url . "api/servers/update", false, $context ) );

?>

 

In the above example, we will edit the server_ip and vpn_ip for our LB with id 2 that already exists in our database.

Example(API Success)

{"result":true, "modified_id":{id}, "name":{name}, "IP address":{server_ip}}

 

Example(API Failed)

{"result":false,"error":"Invalid IP address"}
{"result":false,"error":"{Database error}"}

    Invalid IP address. 
    The provided IP is not a valid IP address
    {Database error}
    Database error description. The DB error will be logged in LOGS -> Panel Error Log.

 

Run SQL Query

Perform this request to run a custom SQL query.

<?php

$panel_url = 'http://DOMAIN:PORT/';
$api_key = 'api_key';
$sql_query = base64_encode('SELECT * FROM `lines`');

###############################################################################

$api_result = json_decode( file_get_contents( $panel_url . "api/run_query/" . $sql_query . "/" . $api_key) );

?>

No POST action is required


--Streams


All rights are reserved to DA Streamz © 2025
MidnightStreamer API
SERVER API STREAMS

To successfully use the Server API, you have to insert your IP first into the whitelist. You can do that in General Settings -> API Settings.

You can pass api_key by POST or by appending the key as 4th segment to the URL.

Getting Online Streams

To get online streams, we will call the following URL.

http(s)://domain:port/api/streams/online/{api_key}

No POST action is required

 

Getting Offline Streams

To get offline streams, we will call the following URL.

http(s)://domain:port/api/streams/offline/{api_key}

No POST action is required

 

Enabling / (Re)starting Streams

To enable/(re)start streams, we will call the following URL.

http(s)://domain:port/api/streams/start/{api_key}/{stream_1_id}/{stream_2_id}/{stream_3_id}/.../{stream_X_id}

No POST action is required

 

Disabling / Stopping Streams

To disable/stop streams, we will call the following URL.

http(s)://domain:port/api/streams/stop/{api_key}/{stream_1_id}/{stream_2_id}/{stream_3_id}/.../{stream_X_id}

No POST action is required

 

Add New Stream

To add a New stream, we will call the following URL.

http(s)://domain:port/api/streams/new

Example Code:

$panel_url = 'http://DOMAIN:PORT/';
$api_key = 'api_key';
$name = 'test';
$urls = ['http://source1:8000/1', 'http://source2:8000/2'];
$categories = [1, 2, 3];
$bouquets = [1, 2, 3];
$servers = [1 => 0, 2 => 1];

###############################################################################
$post_data = array('api_key' => $api_key,
		   'data' => array('name' => $name, 
		   		   'urls' => $urls,
		   		   'categories' => $categories,
		   		   'bouquets' => $bouquets,
		   		   'servers' => $servers)
		   );

$opts = array( 'http' => array(
        'method' => 'POST',
        'header' => 'Content-type: application/x-www-form-urlencoded',
        'content' => http_build_query( $post_data ) ) );

$context = stream_context_create( $opts );
$api_result = json_decode( file_get_contents( $panel_url . "api/streams/new", false, $context ), true );

 

Edit Stream

To edit an existing stream, we will call the following URL.

http(s)://domain:port/api/streams/update

REQUIRED PARAMETERS

    id

Example Code:

$panel_url = 'http://DOMAIN:PORT/';
$api_key = 'api_key';
$id = X;
$urls = ['http://source2:8000/2', 'http://source3:8000/1'];

###############################################################################
$post_data = array( 'api_key' => $api_key, 'id' => $id, 'data' => array('urls' => $urls) );
$opts = array( 'http' => array(
        'method' => 'POST',
        'header' => 'Content-type: application/x-www-form-urlencoded',
        'content' => http_build_query( $post_data ) ) );

$context = stream_context_create( $opts );
$api_result = json_decode( file_get_contents( $panel_url . "api/streams/update", false, $context ), true );

 

Delete Stream

Perform this request to delete a stream.

The URL we will call is

http(s)://domain:port/api/streams/delete

REQUIRED PARAMETERS

    id

Example Code:

$panel_url = 'http://DOMAIN:PORT/';
$api_key = 'api_key';
$id = X;

###############################################################################
$post_data = array( 'api_key' => $api_key, 'id' => $id );
$opts = array( 'http' => array(
        'method' => 'POST',
        'header' => 'Content-type: application/x-www-form-urlencoded',
        'content' => http_build_query( $post_data ) ) );

$context = stream_context_create( $opts );
$api_result = json_decode( file_get_contents( $panel_url . "api/streams/delete", false, $context ), true );

--Panel


All rights are reserved to DA Streamz © 2025
MidnightStreamer API
SERVER API PANEL

To successfully use the Server API, you have to insert your IP first into the whitelist. You can do that in General Settings -> API Settings.
Get Latest Backup Info

Perform this request to view the details of the latest available backup file on remote panel.

http(s)://domain:port/api/panel/last_backup_info/{api_key}

No POST action is required

Example(API Success)

{"result":true, "filename":"{filename}","modified_time":{timestamp},"size":{size},"version":"{version}","sha1":"{sha1}"}

Example(API Failed)

{"result":false,"error":"No files found"}

 

Download Backup

Download the latest backup file.

http(s)://domain:port/api/panel/download_last_backup/{api_key}

No POST action is required

 

API Usage Example

Check backup info and download latest backup file.

<?php

$panel_url = 'http://DOMAIN:PORT/';
$api_key = 'api_key';
$saveDir = __DIR__ . "/backups";
$sha1File = __DIR__ . "/last_backup.sha1";
$backupsCount = 10;

// Ensure backup directory exists
if (!is_dir($saveDir)) {
    mkdir($saveDir, 0755, true);
}

// Step 1: Get last backup info
$opts = array(
    'http' => array(
        'method' => 'GET',
        'header' => "Content-type: application/x-www-form-urlencoded\r\n"
    )
);
$context = stream_context_create($opts);
$api_result = file_get_contents($panel_url . "api/panel/last_backup_info/$api_key", false, $context);

if (!$api_result) {
    die("Failed to get backup info.");
}

$data = json_decode($api_result, true);
if (!$data || !isset($data['sha1'], $data['filename'])) {
    die("Invalid response from backup info API.");
}

$newSha1 = $data['sha1'];
$filename = $data['filename'];
$filepath = $saveDir . '/' . $filename;

// Step 2: Read last saved SHA1
$lastSha1 = file_exists($sha1File) ? trim(file_get_contents($sha1File)) : '';

// Step 3: Compare SHA1
if ($newSha1 === $lastSha1) {
    echo "Backup is up-to-date. SHA1 matches.\n";
    exit;
}

// Step 4: Download new backup
$opts = array(
    'http' => array(
        'method' => 'GET',
        'header' => "Content-type: application/x-www-form-urlencoded\r\n"
    )
);
$context = stream_context_create($opts);
$backupContent = file_get_contents($panel_url . "api/panel/download_last_backup/$api_key", false, $context);

if (!$backupContent) {
    die("Failed to download backup.");
}

// Step 5: Save the backup file
file_put_contents($filepath, $backupContent);

// Step 6: Save new SHA1
file_put_contents($sha1File, $newSha1);

echo "New backup downloaded: $filename\n";
echo "SHA1 updated.\n";

// Step 7: Cleanup old backups (keep only most recent $backupsCount)
$files = glob($saveDir . '/*.gz');

$filesWithDates = [];
foreach ($files as $file) {
    $basename = basename($file);

    // Match YYYY-MM-DD_HH_MM_SS inside filename
    if (preg_match('/(\d{4}-\d{2}-\d{2}_\d{2}_\d{2}_\d{2})/', $basename, $matches)) {
        $dateStr = preg_replace(
            '/(\d{4}-\d{2}-\d{2})_(\d{2})_(\d{2})_(\d{2})/',
            '$1 $2:$3:$4',
            $matches[1]
        );
        $timestamp = strtotime($dateStr);
        if ($timestamp !== false) {
            $filesWithDates[] = [
                'file' => $file,
                'timestamp' => $timestamp
            ];
        }
    } else {
        echo "?? Skipped (no timestamp match): $basename\n";
    }
}

// Sort newest first
usort($filesWithDates, fn($a, $b) => $b['timestamp'] <=> $a['timestamp']);

echo "Total parsed backups: " . count($filesWithDates) . "\n";

// Always keep only $backupsCount
if (count($filesWithDates) > $backupsCount) {
    $oldFiles = array_slice($filesWithDates, $backupsCount);
    foreach ($oldFiles as $entry) {
        if (unlink($entry['file'])) {
            echo "Old backup removed: " . basename($entry['file']) . "\n";
        } else {
            echo "Failed to remove: " . basename($entry['file']) . "\n";
        }
    }
}

--Player API


All rights are reserved to DA Streamz © 2025
MidnightStreamer API
PLAYER API


Note: The API Does not provide Full links to the requested stream. You have to build the url to the stream in order to play it.

    For Live Streams the main format is

           http(s)://domain:port/live/username/password/streamID.ext ( In  allowed_output_formats element you have the available ext )

    For VOD Streams the format is:

    http(s)://domain:port/live/username/password/streamID.ext ( In  target_container element you have the available ext )
     


On the First Authentication Call, you will get a list of some useful elements. If the server_protocol element is https you have to force all the API & Player Requests to be through https. The same Call, also provides the http(s) ports in case you need them as well as the domain name you should use.
The current datetime & timestamps are offered to you and can help you for time corrections for EPG & TV Archive.

If you want to limit the displayed output data, you can use offset / items per page / page number as the last three segments of the API call.

E.g. http(s)://domain:port/api/player/{username}/{password}/live/streams/4/20/7 (fetch streams for user {username} from the 4th stream on, 20 streams per page, fetch the 7th page)

It is higly recommended to fetch all data at once and cache them to your Application.

 

 

Authentication

api/player/{username}/{password}


GET Live Stream Categories

api/player/{username}/{password}/live/categories


GET VOD Stream Categories

api/player/{username}/{password}/vod/categories


GET Series Categories

api/player/{username}/{password}/series_cat (This will get All Series Categories)
api/player/{username}/{password}/series_cat/{category_id} (This will get All Series in the selected category ONLY)

 

GET Live Streams

api/player/{username}/{password}/live/streams (This will get All LIVE Streams)
api/player/{username}/{password}/live/streams/{category_id} (This will get All LIVE Streams in the selected category ONLY)


GET VOD Streams

api/player/{username}/{password}/vod/streams (This will get All VOD Streams)
api/player/{username}/{password}/vod/streams/{category_id} (This will get All VOD Streams in the selected category ONLY)


GET Series Seasons and Episodes

api/player/{username}/{password}/series/seasons/{series_id} (This will get All Seasons of the selected series ONLY)
api/player/{username}/{password}/series/episodes/{series_id}/{season_number} (This will get All Episodes in the selected season of the selected series ONLY)

 


GET Catch-up

api/player/{username}/{password}/catchup/{stream_id} (This will get all catchup info for the choosen stream such as event name, start date, end timestamp, catchup URL and event description)


GET VOD Info

api/player/{username}/{password}/vod/info/{vod_id} (This will get info such as video codecs, duration, description, directors for 1 VOD)


GET Series Episode Info

api/player/{username}/{password}/series/info/{vod_id} (This will get info such as video codecs, duration, description, directors for 1 VOD)

 


GET short epg for LIVE Streams (same as stalker portal, prints the upcoming EPG events that will play next)

api/player/{username}/{password}/epg/short/{stream_id}
api/player/{username}/{password}/epg/short/{stream_id}/{offset}/{items_per_page}/{page_number} (You can specify a limit too by appending offset/items_per_page/page_number to the URL)


 GET ALL EPG for LIVE Streams (same as stalker portal, but it will print all EPG listings regardless of the day)

api/player/{username}/{password}/epg/full/{stream_id}


Full EPG List for all Streams

api/player/{username}/{password}/epg/full/all


Get Archive URL

api/player/{username}/{password}/archive/create_link/{stream_id}/{epg_event_end}

 

Get EPG Date TXT File

download/LastUpdate/{username}/{password}

 

Get EPG Timestamp TXT File

download/LastUpdateTimestamp/{username}/{password}

 

Get Line Messages

api/player/{username}/{password}/messages

 

Send Claims

api/player/{username}/{password}/send_claim/{stream_id}/{claim_type} (claim_type can be sound, video, no_epg, wrong_epg)

 

Set Favorites for Live channels, VOD and Radio

api/player/{username}/{password}/set_fav/{live/vod/radio}/{service_1_id}/{service_2_id}/{service_3_id}/...

 

Set Favorites for Series

api/player/{username}/{password}/set_fav/series/{series_1_id}/{series_2_id}/{series_3_id}/...

 

Check Parent Password

api/player/{username}/{password}/check_parent_password/{password} (returns True or False)

 

Change Parent Password

api/player/{username}/{password}/change_parent_password/{current_parent_password}/{new_parent_password} (returns False is current_parent_password is wrong)

 

Get Speed Test URL

api/player/{username}/{password}/speed_test

 

Download arbitrary File located in folder /home/midnightstreamer/iptv_midnight_streamer/download

download/file/{username}/{password}/{file_name}

--Hooks


All rights are reserved to DA Streamz © 2025
MidnightStreamer API
HOOKS

Hooks are used to customize the Panel behaviour based on event type.

Hook files are located in the /home/midnightstreamer/iptv_midnight_streamer/wwwdir/application/hooks directory and have to be prefixed by the custom_ keyword.

The add_hook function is used to register the callback functions.

 

Syntax

add_hook(string $event_type, integer $priority, string $callback_function)

 

Available Event Types are 

    line/disable_line
    line/enable_line
    mag/disable_mag
    mag/enable_mag

 
The callback functions execution order is defined by the priority parameter.

 
The callback functions have two array type parameters available for processing, $segments which contains the URL segments from the 3rd segment on and $post array which contains POST data.

 

For example if we want to call an API on another server while disabling/enabling a Line or MAG Device in our Panel, we can make a hook like this:

<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

function disable_line($segments, $post)
{
		$CI =& get_instance();

		$line = $CI->lines_model->get_line($segments[0]);

		call_api('https://server.com:8001/', 'API_KEY', 'api/line/update', array('username' => $line->username, 'disabled' => 1));
}

function enable_line($segments, $post)
{
		$CI =& get_instance();

		$line = $CI->lines_model->get_line($segments[0]);

		call_api('https://server.com:8001/', 'API_KEY', 'api/line/update', array('username' => $line->username, 'disabled' => 0));
}

function disable_mag($segments, $post)
{
		$CI =& get_instance();

		$mac_address = $CI->mags_model->get_mag_mac_by_id($segments[0]);

		call_api('https://server.com:8001/', 'API_KEY', 'api/mag/update', array('mac_address' => $mac_address, 'disabled' => 1));
}

function enable_mag($segments, $post)
{
		$CI =& get_instance();

		$mac_address = $CI->mags_model->get_mag_mac_by_id($segments[0]);

		call_api('https://server.com:8001/', 'API_KEY', 'api/mag/update', array('mac_address' => $mac_address, 'disabled' => 0));
}

add_hook('line/disable_line', 1, 'disable_line');
add_hook('line/enable_line', 1, 'enable_line');

add_hook('mag/disable_mag', 1, 'disable_mag');
add_hook('mag/enable_mag', 1, 'enable_mag');

?>